lib/deploy: Port various functions to declare-and-initialize
authorColin Walters <walters@verbum.org>
Fri, 16 Mar 2018 01:15:51 +0000 (21:15 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Sat, 17 Mar 2018 20:36:04 +0000 (20:36 +0000)
Just noticed this while working on the code.

Closes: #1499
Approved by: jlebon

src/libostree/ostree-sysroot-deploy.c
src/libostree/ostree-sysroot.c

index f0a667d77e74b26b1d504b9cc6ee8b2483c65341..9aa720aac4f753abc4e49eb84f89123bab9bdc25 100644 (file)
@@ -667,27 +667,21 @@ selinux_relabel_dir (OstreeSysroot                 *sysroot,
                      GCancellable                  *cancellable,
                      GError                       **error)
 {
-  gboolean ret = FALSE;
-  g_autoptr(GPtrArray) path_parts = g_ptr_array_new ();
-  g_autoptr(GFileInfo) root_info = NULL;
 
-  root_info = g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO,
-                                 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                 cancellable, error);
+  g_autoptr(GFileInfo) root_info =
+    g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO,
+                       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                       cancellable, error);
   if (!root_info)
-    goto out;
+    return FALSE;
 
+  g_autoptr(GPtrArray) path_parts = g_ptr_array_new ();
   g_ptr_array_add (path_parts, (char*)prefix);
   if (!relabel_recursively (sysroot, sepolicy, dir, root_info, path_parts,
                             cancellable, error))
-    {
-      g_prefix_error (error, "Relabeling /%s: ", prefix);
-      goto out;
-    }
+    return glnx_prefix_error (error, "Relabeling /%s", prefix);
 
-  ret = TRUE;
- out:
-  return ret;
+  return TRUE;
 }
 
 /* Handles SELinux labeling for /var; this is slated to be deleted.  See
@@ -766,12 +760,7 @@ merge_configuration (OstreeSysroot         *sysroot,
 
   if (previous_deployment)
     {
-      g_autoptr(GFile) previous_path = NULL;
-      OstreeBootconfigParser *previous_bootconfig;
-
-      previous_path = ostree_sysroot_get_deployment_directory (sysroot, previous_deployment);
-
-      previous_bootconfig = ostree_deployment_get_bootconfig (previous_deployment);
+      OstreeBootconfigParser *previous_bootconfig = ostree_deployment_get_bootconfig (previous_deployment);
       if (previous_bootconfig)
         {
           const char *previous_options = ostree_bootconfig_parser_get (previous_bootconfig, "options");
@@ -1939,23 +1928,18 @@ deployment_bootconfigs_equal (OstreeDeployment *a,
     return FALSE;
 
   {
+    /* We checksum the kernel arguments *except* ostree= */
     OstreeBootconfigParser *a_bootconfig = ostree_deployment_get_bootconfig (a);
-    OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b);
     const char *a_boot_options = ostree_bootconfig_parser_get (a_bootconfig, "options");
-    const char *b_boot_options = ostree_bootconfig_parser_get (b_bootconfig, "options");
-    g_autoptr(OstreeKernelArgs) a_kargs = NULL;
-    g_autoptr(OstreeKernelArgs) b_kargs = NULL;
-    g_autofree char *a_boot_options_without_ostree = NULL;
-    g_autofree char *b_boot_options_without_ostree = NULL;
-
-    /* We checksum the kernel arguments *except* ostree= */
-    a_kargs = _ostree_kernel_args_from_string (a_boot_options);
+    g_autoptr(OstreeKernelArgs) a_kargs = _ostree_kernel_args_from_string (a_boot_options);
     _ostree_kernel_args_replace (a_kargs, "ostree");
-    a_boot_options_without_ostree = _ostree_kernel_args_to_string (a_kargs);
+    g_autofree char *a_boot_options_without_ostree = _ostree_kernel_args_to_string (a_kargs);
 
-    b_kargs = _ostree_kernel_args_from_string (b_boot_options);
+    OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b);
+    const char *b_boot_options = ostree_bootconfig_parser_get (b_bootconfig, "options");
+    g_autoptr(OstreeKernelArgs) b_kargs = _ostree_kernel_args_from_string (b_boot_options);
     _ostree_kernel_args_replace (b_kargs, "ostree");
-    b_boot_options_without_ostree = _ostree_kernel_args_to_string (b_kargs);
+    g_autofree char *b_boot_options_without_ostree = _ostree_kernel_args_to_string (b_kargs);
 
     if (strcmp (a_boot_options_without_ostree, b_boot_options_without_ostree) != 0)
       return FALSE;
@@ -2086,12 +2070,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
                                                GError           **error)
 {
   gboolean ret = FALSE;
-  guint i;
-  gboolean requires_new_bootversion = FALSE;
-  gboolean found_booted_deployment = FALSE;
-  gboolean bootloader_is_atomic = FALSE;
   gboolean boot_was_ro_mount = FALSE;
-  SyncStats syncstats = { 0, };
   g_autoptr(OstreeBootloader) bootloader = NULL;
 
   g_assert (self->loaded);
@@ -2105,11 +2084,12 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
    * matching bootloader configuration, then we can just swap the
    * subbootversion bootlinks.
    */
+  gboolean requires_new_bootversion = FALSE;
   if (new_deployments->len != self->deployments->len)
     requires_new_bootversion = TRUE;
   else
     {
-      for (i = 0; i < new_deployments->len; i++)
+      for (guint i = 0; i < new_deployments->len; i++)
         {
           if (!deployment_bootconfigs_equal (new_deployments->pdata[i],
                                              self->deployments->pdata[i]))
@@ -2120,7 +2100,8 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
         }
     }
 
-  for (i = 0; i < new_deployments->len; i++)
+  gboolean found_booted_deployment = FALSE;
+  for (guint i = 0; i < new_deployments->len; i++)
     {
       OstreeDeployment *deployment = new_deployments->pdata[i];
       g_autoptr(GFile) deployment_root = NULL;
@@ -2146,6 +2127,8 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
       goto out;
     }
 
+  gboolean bootloader_is_atomic = FALSE;
+  SyncStats syncstats = { 0, };
   if (!requires_new_bootversion)
     {
       if (!create_new_bootlinks (self, self->bootversion,
@@ -2211,13 +2194,10 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
 
       /* Only show the osname in bootloader titles if there are multiple
        * osname's among the new deployments.  Check for that here. */
-      for (i = 1; i < new_deployments->len; i++)
+      for (guint i = 1; i < new_deployments->len; i++)
         {
-          const gchar *osname_0, *osname_i;
-
-          osname_0 = ostree_deployment_get_osname (new_deployments->pdata[0]);
-          osname_i = ostree_deployment_get_osname (new_deployments->pdata[i]);
-
+          const char *osname_0 = ostree_deployment_get_osname (new_deployments->pdata[0]);
+          const char *osname_i = ostree_deployment_get_osname (new_deployments->pdata[i]);
           if (!g_str_equal (osname_0, osname_i))
             {
               show_osname = TRUE;
@@ -2225,7 +2205,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
             }
         }
 
-      for (i = 0; i < new_deployments->len; i++)
+      for (guint i = 0; i < new_deployments->len; i++)
         {
           OstreeDeployment *deployment = new_deployments->pdata[i];
           if (!install_deployment_kernel (self, repo, new_bootversion,
index 1cf7779ae04832b3593097c9112af1e3561ee150..f77d7703718b8bcc01372b7a41bed52ac476271f 100644 (file)
@@ -690,30 +690,25 @@ parse_deployment (OstreeSysroot       *self,
   return TRUE;
 }
 
+/* Given a bootloader config, return the value part of the ostree= kernel
+ * argument.
+ */
 static char *
 get_ostree_kernel_arg_from_config (OstreeBootconfigParser  *config)
 {
-  const char *options;
-  char *ret = NULL;
-  char **opts, **iter;
-
-  options = ostree_bootconfig_parser_get (config, "options");
+  const char *options = ostree_bootconfig_parser_get (config, "options");
   if (!options)
     return NULL;
 
-  opts = g_strsplit (options, " ", -1);
-  for (iter = opts; *iter; iter++)
+  g_auto(GStrv) opts = g_strsplit (options, " ", -1);
+  for (char **iter = opts; *iter; iter++)
     {
       const char *opt = *iter;
       if (g_str_has_prefix (opt, "ostree="))
-        {
-          ret = g_strdup (opt + strlen ("ostree="));
-          break;
-        }
+        return g_strdup (opt + strlen ("ostree="));
     }
-  g_strfreev (opts);
 
-  return ret;
+  return NULL;
 }
 
 static gboolean
@@ -963,13 +958,10 @@ ostree_sysroot_get_booted_deployment (OstreeSysroot       *self)
 GPtrArray *
 ostree_sysroot_get_deployments (OstreeSysroot  *self)
 {
-  GPtrArray *copy;
-  guint i;
-
   g_return_val_if_fail (self->loaded, NULL);
 
-  copy = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
-  for (i = 0; i < self->deployments->len; i++)
+  GPtrArray *copy = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
+  for (guint i = 0; i < self->deployments->len; i++)
     g_ptr_array_add (copy, g_object_ref (self->deployments->pdata[i]));
   return copy;
 }
@@ -1114,10 +1106,9 @@ char *
 _ostree_sysroot_join_lines (GPtrArray  *lines)
 {
   GString *buf = g_string_new ("");
-  guint i;
   gboolean prev_was_empty = FALSE;
 
-  for (i = 0; i < lines->len; i++)
+  for (guint i = 0; i < lines->len; i++)
     {
       const char *line = lines->pdata[i];
       /* Special bit to remove extraneous empty lines */